package com.yvan.serverless.mybatis;

//import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSource;
import com.yvan.dynamic.datasource.DynamicRoutingDataSource;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class DataSourceHelper implements ApplicationContextAware {

    public static ApplicationContext APPLICATION;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        APPLICATION = applicationContext;
    }

    public static String getDbType() {
        try {
            DynamicRoutingDataSource ds = APPLICATION.getBean(DynamicRoutingDataSource.class);
            DruidDataSource druidDataSource = ds.determineDataSource().unwrap(DruidDataSource.class);
            return druidDataSource.getDbType();

        } catch (Exception e) {
            return "mysql";
        }
    }
}
